<template>
  <div class="buysteps container">
    <el-steps :active="activenum" finish-status="success" simple style="margin-top: 20px">
      <el-step title="完成订单信息" ></el-step>
      <el-step title="收银台" ></el-step>
    </el-steps>
    <div class="ddinfo">
      <div class="cont" >
        <div class="head">
          <p>订单信息</p>
        </div>
        <p class="p1">订单号：{{this.$route.query.ddh}}</p>
        <p class="p1">总金额：<span>￥{{this.$route.query.ddjg}}</span></p>
        <div class="sure wx" @click="getinfo()">微信付款</div>
        <div class="sure zfb" @click="zfbgetinfo()">支付宝付款</div>
      </div>
    </div>
    <div class="fixed" :class="{active:index == 1}">
      <div class="fffbox">
        <i class="el-icon-close" @click="dj()"></i>
        <div id="qrcode"></div>
        <p>扫描二维码支付</p>
      </div>
    </div>
  </div>
</template>

<script>
import ban1 from '@/assets/image/ban1.jpg';
import cp1 from '@/assets/image/cp1.jpg';
import qs from "qs"
import store from '@/vuex/store'
import QRCode from 'qrcodejs2'
export default {
  name: 'App',
  data(){
    return{
      activenum:1,
      index: 0,
      ewm:'',
      dd:false,
      lk: false
    }
  },
  methods:{
    getinfo:function(){
      this.$http.post("/index.php/user/order/pay",qs.stringify({
          // mobile:this.tel,
          // password:this.pwd
          order_number: this.$route.query.ddh

      }))
      .then(res => {
        console.log(res)
        this.index = 1;
        this.ewm = res.data
        if(this.dd == false){
          this.qrcode();
          this.dd = true;
          this.$http.get("/index.php/user/order/get_pay_order_number?order_number="+this.$route.query.ddh)
          .then(res => {
            
            console.log(res.data.info.order_number)
            this.fscheked(res.data.info.order_number);
          })
          
        }else{
          return
        }
      })
      .catch(error => {
        alert("网络错误")
      });
      
    },
    zfbgetinfo:function(){
      this.$http.post("/index.php/user/order/webAliPay",qs.stringify({
          // mobile:this.tel,
          // password:this.pwd
          order_number: this.$route.query.ddh

      }))
      .then(res => {
        console.log(res.data);
        window.location.href = res.data
        
        // this.index = 1;
        // this.ewm = res.data
        // if(this.dd == false){
        //   this.qrcode();
        //   this.dd = true;
        //   this.fscheked();
        // }else{
        //   return
        // }
      })
      .catch(error => {
        alert("网络错误")
      });
    },
    fscheked:function(num){
      if (this && !this._isDestroyed) {
      window.Interval = setInterval(()=>{
        this.$http.post("/index.php/user/order/query_order",qs.stringify({
            // mobile:this.tel,
            // password:this.pwd
            // order_number: this.$route.query.ddh
            order_number: num

        }))
        .then(res => {
          // console.log(res)
          console.log(res.data.row.trade_state_desc)
          if(res.data.row.trade_state_desc=='支付成功'){
            clearInterval(window.Interval)
            this.$alert('可以去个人订单查看信息', '支付成功！', {
              confirmButtonText: '确定',
              callback: action => {
                
              }
            });
            this.index = 0;
          }

        })
        .catch(error => {
          alert("网络错误")
        });
      },1000);
      }
    },
    qrcode:function() {
      const that =this;
      console.log(that.ewm);
      let qrcode = new QRCode('qrcode', {
        width: 200,
        height: 200, // 高度
        text: that.ewm //'weixin://wxpay/bizpayurl?pr=Py2ThBl' // 二维码内容
        // render: 'canvas' // 设置渲染方式（有两种方式 table和canvas，默认是canvas）
        // background: '#f0f'
        // foreground: '#ff0'
      })
      console.log(qrcode)
    },
    dj:function(){
      this.index = 0;
    }

  },
  components:{

  },
  computed:{
      
  },
  filters: {
    
  },
  mounted(){
      
  },
  created(){
    
  },
  destroyed: function () {
    console.log(111)
  },
  beforeRouteLeave(to, from, next){
                console.log('离开当前组件所在路由时触发')
                if (window.Interval) {
                  clearInterval(window.Interval)
                }
                next()
              },
  watch:{
    '$route' (to, from) {
                // this.getinfo()
               //   const toDepth = to.path.split('/').length
                // const fromDepth = from.path.split('/').length
                // this.transitionName = toDepth < fromDepth ? 'slide-right' : 'slide-left'
                // console.log(to.name)
                
                if(to.path == '/buypage'){
                  
                }
              }

  }
}
</script>

<style scoped lang="less">
.buysteps{
  margin-top: 3px;
  height: auto;
  zoom: 1;
  overflow: hidden;
}

.fixed{
  position: fixed;
  z-index: 99999999;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,.7);
  left: 0;
  top: 0;
  display: none;
  .fffbox{
    i{
      font-size: 18px;
      font-weight: bold;
      color: #333;
      padding-top: 10px;
      padding-right: 10px;
      cursor: pointer;
    }
    text-align: right;
    background: #fff;
    width: 300px;
    height: 300px;
    position: absolute;
    left: 50%;
    margin-left: -150px;
    top: 50%;
    margin-top: -150px;
    z-index: 1;
    div{
      margin-left: 50px;
      margin-top: 14px;
    }
    p{
      font-size: text-align;
      font-size: 16px;
      color: #333;
      margin-top: 16px;
      display: block;
      text-align: center;
    }
  }
  
}
.active{
  display: block;
}
.ddinfo{
  width: 100%;
  height: auto;
  float: left;
  box-sizing: border-box;
  border: 1px solid #d6d6d6;
  margin-top: 30px;
  margin-bottom: 50px;
  .cont{
      padding: 30px 140px;
      .head{
        width: 100%;
        height: auto;
        border-bottom: 1px solid #d3d3d3;
        p{
          font-size: 20px;
          font-weight: bold;
          padding-bottom: 14px;
        }
      }
      .p1{
        display: block;
        font-size: 18px;
        color: #333;
        padding-top: 20px;
        span{
          font-size: 24px;
          color: #f31936;
          font-weight: bold;
        }
      }
      .sure{
        width: 140px;
        height: 48px;
        cursor:pointer;
        background: #f31936;
        color: #fff;
        text-align: center;
        line-height: 48px;
        font-size: 16px;
        margin-top: 24px;
        margin-bottom: 20px;
      }
      .wx{
        background: #62b900;
        float: left;
      }
      .zfb{
        background: #108ee9;
        float: left;
        margin-left: 20px;
      }
  }
}

</style>
